import { APPID, APPSECRET, AUTHORIZATIONCODE, CLIENTCREDENTIAL } from '../config/config';

module.exports = class extends think.Service {
  constructor(code) {
    super();
    this.code = code;
  }
  async getopenid() {
    const url = `https://api.weixin.qq.com/sns/jscode2session?appid=${APPID}&secret=${APPSECRET}&js_code=${this.code}&grant_type=${AUTHORIZATIONCODE}`;
    const json = await this.fetch(url).then(res => res.json());
    return json;
  }
  async getAccessToken() {
    const url = `https://api.weixin.qq.com/cgi-bin/token?grant_type=${CLIENTCREDENTIAL}&appid=${APPID}&secret=${APPSECRET}`;
    const json = await this.fetch(url).then(res => res.json());
    return json;
  }
};
